/**
 * 
 */
package com.kcwx.common.utils;

import java.math.BigDecimal;

/**
 * @author Admin
 *
 */
public class CalculateUtils {

	public static String percentageCalculator(BigDecimal num, BigDecimal totalNum) {
		String res = "";
		if (num != null && totalNum != null && num.compareTo(new BigDecimal("0")) != 0
				&& totalNum.compareTo(new BigDecimal("0")) != 0) {
			return num.divide(totalNum, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))
					.setScale(2, BigDecimal.ROUND_HALF_UP).toString() + "%";
		}
		return res;
	}

	public static void main(String[] args) {
		BigDecimal num = new BigDecimal("1");
		BigDecimal totalNum = new BigDecimal("3");
		System.out.println(percentageCalculator(num, totalNum));
	}
}
